// 1. createRouter 生成router实例对象
// 2. createWebHashHistory 生成hash模式的路由配置对象

import { createRouter, createWebHashHistory } from 'vue-router'
// 路由如果需要按需导入的话 减少初始化加载包的时间 可以进行动态导入！
import Layout from '@/views/Layout'
import Login from '@/views/Login'
import Category from '@/views/Category'
import Home from '@/views/Home'
import Good from '@/views/Good'
import Cart from '@/views/Cart'
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '', // 为什么要留空？当二级路由的path置空的时候 将作为默认二级路由出口
        component: Home,
        name: 'home'
      },
      {
        path: 'category/:id',
        component: Category,
        name: 'category'
      },
      {
        path: 'good/:id',
        component: Good,
        name: 'good'
      },
      {
        path: 'cart',
        component: Cart,
        name: 'cart'
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
